function sum(){
    var cur = [].slice.call(arguments).reduce(function(a,b){return a+b;},0);
    function innerSum(){
      var next = [].slice.call(arguments).reduce(function(a,b){return a+b;},0);
      cur += next;
      return innerSum;
    }
    innerSum.sameOf = function(){
      return cur;
    }
    return innerSum;
}

// function sum () {
//     let cur = [].slice.call(arguments).reduce((a, b) => a + b, 0)
//     function innerSum () {
//         let next = [].slice.call(arguments).reduce((a, b) => a + b, 0)
//         cur += next
//         return innerSum
//     }

//     innerSum.getValueOf = function () {
//         return cur
//     }

//     return innerSum
// }

console.log(sum(1,2,3).sameOf());       //6
// console.log(sum(2,3)(2).getValueOf());      //7
// console.log(sum(1)(2)(3)(4).getValueOf());  //10
// console.log(sum(2)(4,1)(2).getValueOf());   //9